package com.springboot.frame.web.page;

import java.io.Serializable;

/**
 * @Author 孟玖林
 * @Date 2019/6/3 10:28 AM
 * @Description
 */
public class PageInfo implements Serializable {
    private static final long serialVersionUID = 1L;
    private int totalCount;//总记录数据
    private int currentPage = 1;//当前页码
    private int pageShowCount = 10;//每页显示数量
    private int totalPage=0;//总页数
    private boolean hasNextPage;
    private boolean hasPrevPage;
    public PageInfo(){}
    public PageInfo(int currentPage,int pageShowCount,int totalCount){
        super();
        this.currentPage = currentPage == 0 ? 1 : currentPage;
        this.totalCount = totalCount;
        this.pageShowCount = pageShowCount == 0 ? 10 : pageShowCount;
        this.totalPage = getTotalPage(pageShowCount,totalCount);
        this.hasNextPage = hasNextPage(currentPage,this.totalPage);
        this.hasPrevPage = hasPrevPage(currentPage);

    }
    public int getTotalCount() {
        return totalCount;
    }
    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }
    public int getCurrentPage() {
        return currentPage;
    }
    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }
    public int getPageShowCount() {
        return pageShowCount;
    }
    public void setPageShowCount(int pageShowCount) {
        this.pageShowCount = pageShowCount;
    }
    public int getTotalPage() {
        return totalPage;
    }
    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }
    public boolean getHasNextPage() {
        return hasNextPage;
    }
    public void setHasNextPage(boolean hasNextPage) {
        this.hasNextPage = hasNextPage;
    }
    public boolean getHasPrevPage() {
        return hasPrevPage;
    }
    public void setHasPrevPage(boolean hasPrevPage) {
        this.hasPrevPage = hasPrevPage;
    }

    public static int getTotalPage(int pageShowCount, int totalCount) {
        int totalPage = 0;
        if (totalCount % pageShowCount == 0){
            totalPage = totalCount / pageShowCount;
        } else{
            totalPage = totalCount / pageShowCount + 1;
        }
        return totalPage;
    }

    private static boolean hasNextPage(int currentPage, int totalPage) {
        return currentPage >= totalPage || totalPage == 0 ? false : true;
    }

    private static boolean hasPrevPage(int currentPage) {
        return currentPage == 1 ? false : true;
    }
}
